﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using PPIDesktopClient.Logic;
using System.ComponentModel;

namespace PPIDesktopClient.General
{
    public class SaveUtilityProcess : Process
    {
        EUtility_Asset_XMissionStructure   m_asset;
        int m_TotalInformation;
        int m_UploadInformation;

        public SaveUtilityProcess(EUtility_Asset_XMissionStructure asset) 
        {
            m_asset = asset;
            CalculateteTotalData();
        }
        private void CalculateteTotalData()
        {
            m_TotalInformation = 1;
            m_TotalInformation += m_asset.Images.Count;
            m_TotalInformation += m_asset.Poles.Count;
        }

        public override void StartProcess()
        {
            if (!m_ProcessWorker.IsBusy)
            {
                m_ProcessWorker.RunWorkerAsync();
            }
        }
        protected override void Work()
        {
            LUtility_Asset_XMissionStructure logic = new LUtility_Asset_XMissionStructure();
            logic.SaveImage += new EventHandler(logic_SaveImage);
            logic.SavePole += new EventHandler(logic_SavePole);
            logic.SaveStructure += new EventHandler(logic_SaveStructure);
            logic.Update(m_asset);
        }

        #region Events
        void logic_SaveStructure(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation, m_TotalInformation), new object()));

        }

        void logic_SavePole(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation, m_TotalInformation), new object()));

        }

        void logic_SaveImage(object sender, EventArgs e)
        {
            m_UploadInformation++;
            OnSaveProgressChanged(sender, new ProgressChangedEventArgs(CalculateProgress(m_UploadInformation, m_TotalInformation), new object()));

        } 
        #endregion
    }
}
